import pymssql
import json
from tools import config

server = config.mssqldbinfo['host']
user = config.mssqldbinfo['user']
password = config.mssqldbinfo['passwd']
db = config.mssqldbinfo['db']

def getdata(sql,is_dic = True):
   conn = pymssql.connect(server, user, password, db)
   if is_dic:
      cursor = conn.cursor(as_dict=True)
   else:
      cursor = conn.cursor()
   cursor.execute(sql, [])
   alldata = cursor.fetchall()
   conn.close()
   return alldata

def getdata_param(sql,param):
   conn = pymssql.connect(server, user, password, db)
   cursor = conn.cursor(as_dict=True)
   cursor.execute(sql, param)
   alldata = cursor.fetchall()
   conn.close()
   return alldata